// 获取所有数据含子表单
export const getEasyTableDataWithChildren = async () => {
  const easyTableData = getEasyData(3) as any[];
  easyTableData.forEach((row) => {
    row.children = getExtraData(2);
  });

  return then(easyTableData);
};

// 获取所有数据不含子表单
export const getEasyTableDataOnly = async () => {
  return then(getEasyData(3));
};

// 保存所有数据
export const saveEasyTableData = (...args: any) => {
  then(true);
};
// 保存单个数据
export const saveEasyTableDataWithId = () => {
  then(true);
};

// 获取所有
export const getExtraTableDataWithParentId = (id: string) => {
  return then(getExtraData(3));
};
// 保存所有
export const saveExtraTableData = (...args: any) => {
  return then(true);
};
// 保存单个
export const saveExtraTableDataWithId = (...args: any) => {
  return then(true);
};

export function then<T>(data: T, delay = 500) {
  return new Promise<T>((resolve) => {
    setTimeout(() => {
      resolve(data);
    }, delay);
  });
}

function getData(
  type: 'easy' | 'extra',
  count: number = 4,
  state: '审核中' | '未提交' = '未提交'
) {
  const items = {
    easy: {
      index: 1,
      customer: '芜湖美芝',
      orderCode: 'd9827349827',
      productsType: '成品',
      orderType: '销售订单',
      total: 0,
      weight: 0,
      created: new Date().toLocaleDateString(),
      seller: '某偶某',
      state,
    },
    extra: {
      index: 1,
      orderCode: 123,
      priority: 100,
      needs: 5000,
      standard: '美芝',
      mode: 'abc/13',
      spec: '0.025',
      reel: 'idk12',
      dish: '2*2',
      date: new Date().toLocaleDateString(),
      pack: '木托',
      mark: '',
      send: true,
      sends: 1000,
      prod: false,
      prods: 2000,
    },
  };

  const item = items[type];
  const data: any[] = [];

  for (let i = 0; i < count; i++) {
    if (i % 2 === 0) {
      data.push({ ...item, state: '审核中' });
    } else {
      data.push(item);
    }
  }

  return data;
}

function getEasyData(
  count: number = 4,
  state: '审核中' | '未提交' = '未提交'
) {
  const data = getData('easy', count, state);
  return data;
}

function getExtraData(count: number = 4) {
  const data = getData('extra', count);
  return data;
}
